
import { makeAutoObservable } from 'mobx'
class TaskStore {
  list = [
    {
      id: 1,
      name: '学习react',
      isDone: true
    },
    {
      id: 2,
      name: '搞定mobx',
      isDone: true
    }
  ]
  constructor() {
    makeAutoObservable(this)
  }

  // 单选功能
  checked = id => {
    // 筛选目标数组
    const item = this.list.find(item => item.id === id)
    // 取反赋值
    item.isDone = !item.isDone
  }
  // 判断是否全选功能
  get allChecked() {
    return this.list.every(item => !item.isDone)
  }
  // 全选控制单选
  itemChecked = val => {
    console.log(val)
    this.list.forEach(item => item.isDone = !val)
  }
  // 添加
  addItem = item => {
    this.list.unshift(item)
  }
  // 删除
  delItem = id => {
    this.list = this.list.filter(item => item.id !== id)
  }
  // 统计已经完成数量
  get okItemCount() {
    return this.list.filter(item => !item.isDone).length
  }
}
export default TaskStore
